package solution;

public class T0112_2_FactorialSum {
    //给定一个整数n，求解（1!+2!+3!+4!+5!+…+n!) %10000
    //提示：
    //1.（a + b) % x = a % x + b % x
    //2.（a * b) % x = (a % x) * (b % x)
    public int factorialSum(int n) {
        int mod = 10000; // 取模 10000
        int sum = 0;

        int last = 1;
        for (int i = 1; i <= n; i++) {
            int factorial = last * i % mod;
            sum = (sum + factorial) % mod; // 累加结果时取模
            last = factorial;
        }
        return sum;
    }

}
